<?
    class PrincipioAuthAdapter implements Zend_Auth_Adapter_Interface
    {
        private $_username;
        private $_password;

        public function __construct ($username, $password)
        {
            $this->_username = $username;
            $this->_password = $password;
        }
        
        public function authenticate ()
        {
            if (($this->_username == "admin") && ($this->_password == "123456") )
                return new Zend_Auth_Result(Zend_Auth_result::SUCCESS, $this->_username);
            else
                return new Zend_Auth_Result(Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID, "");
        }
    }
    
    class AuthController extends Zend_Controller_Action
    { 
        public function indexAction ()
        {
            $authAdapter = "";
            $result = "";
            $auth = "";

            $this->_helper->layout->setLayout("login");

            if ($data = $this->getRequest()->getParams()) 
            {
                if (isset($data["enter"]))
                {
                    $auth = Zend_Auth::getInstance();
                    $authAdapter = new PrincipioAuthAdapter($data["login"], $data["password"]);
                    $result = $auth->authenticate($authAdapter);

                    if ($result->isValid())
                    {
                        $this->_redirect("/");
                    }
                    else
                    {
                        $this->view->errorMsg = "Invalid Login/Password";
                    };
                };
            };
        }


        public function logoutAction ()
        {
            Zend_Auth::getInstance()->clearIdentity();
            $this->_redirect("/auth");
        }
	}
